package modele.agent;

import modele.cases.Case;
import modele.cases.CaseInterface;

public class AgentSim_1 implements AgentInterface {

	private boolean stateFuture;
	private boolean stateNow;
	private CaseInterface agentCase;
	private int id;

	@Override
	public int getId() {
		return id;
	}

	@Override
	public CaseInterface getAgentCase() {
		return agentCase;
	}

	public AgentSim_1(int id) {
		this.id = id;
		double d = Math.random();
		stateNow = true;
		if (d < 0.6) {
			stateNow = false;
		}
	}

	@Override
	public void doStep() {
		int nbAliveNeighbours = agentCase.getNbAliveAround();
		if (stateNow == false) {
			if (nbAliveNeighbours == 3) {
				stateFuture = true;
			}
		} else {
			if (nbAliveNeighbours > 3 || nbAliveNeighbours < 2) {
				stateFuture = false;
			}
		}
	}

	@Override
	public void finalizeStep() {
		stateNow = stateFuture;

	}

	@Override
	public void setAgentCase(Case agentCase) {
		this.agentCase = agentCase;

	}

	@Override
	public boolean isAlive() {
		return stateNow;
	}

}
